/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slowotok;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.ardverk.collection.PatriciaTrie;
import org.ardverk.collection.StringKeyAnalyzer;
import org.ardverk.collection.Trie;

/**
 *
 * @author PiotrGl
 */
public class Slownik {
    //private SortedMap<String, String> slownik = new TreeMap<String, String>();
    private Trie<String, String> slownik = new PatriciaTrie<String, String>(StringKeyAnalyzer.INSTANCE);
    //private String slownik = "";

    public Slownik() {
        System.out.println("ładownaie słownika do pamięci");
        init();
        System.out.println("załadowano");
    }
    
    private void init(){
        try {
            File file = new File("C:/Users/PiotrGl/Documents/NetBeansProjects/slowotok/slowa-win.txt");
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            while ((line = br.readLine()) != null) {
                slownik.put(line, line);
                //slownik+="^"+line;
                //System.out.println(slownik.length());
            }
            br.close();
        } catch (IOException e){
            System.out.println("blad wyczytywania slownika" + e);
        }
    }
    
    public boolean isInDictionary(String s){
        //return slownik.contains("^"+s);
        Map.Entry<String, String> ret = slownik.select(s.toLowerCase());
        if (ret.getKey().startsWith(s.toLowerCase()))
            return true;
        else 
            return false;
    }
    
     public String getDictionaryWord(String s){
        //return slownik.contains("^"+s);
        Map.Entry<String, String> ret = slownik.select(s.toLowerCase());
        return ret.getKey();
    }
}
